package com.melody.rest.config;

import com.melody.rest.util.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


import javax.annotation.Resource;

@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Resource
    RedisTemplate redisTemplate;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        //配置登录查看是否有token拦截器
        registry.addInterceptor(new LoginInterceptor(redisTemplate)).addPathPatterns("/testRest/**").order(0);




        // 登录拦截器
/*        registry.addInterceptor(new LoginInterceptor())
                .excludePathPatterns(//排除下面不需要拦截
                        "/shop/**",
                        "/voucher/**",
                        "/shop-type/**",
                        "/upload/**",
                        "/blog/hot",
                        "/user/code",
                        "/user/login"
                ).order(1);*/
        //order()配置这个拦截器执行顺序，值越大，优先级越低
        // token刷新的拦截器
        //,addPathPatterns//添加拦截/**拦截全部，默认不写也是拦截全部请求
        //registry.addInterceptor(new InterceptorRegistry(stringRedisTemplate)).addPathPatterns("/**").order(0);

    }
}
